package com.gxuwz.stats.service.excelNewHandler;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.gxuwz.stats.entity.AchievementTransfer;
import com.gxuwz.stats.entity.dto.AchievementTransferGXDTO;
import com.gxuwz.stats.service.excelhandler.ImportResultProvider;
import com.gxuwz.stats.service.impl.AchievementTransferServiceImpl;
import java.util.ArrayList;
import java.util.List;

public class AchievementTransferGXListener extends AnalysisEventListener<AchievementTransferGXDTO> implements ImportResultProvider {
    private final List<AchievementTransfer> dataList = new ArrayList<>();
    private final AchievementTransferServiceImpl service;
    private final String username, role, department;

    public AchievementTransferGXListener(AchievementTransferServiceImpl service, String username, String role, String department) {
        this.service = service;
        this.username = username;
        this.role = role;
        this.department = department;
    }

    @Override
    public void invoke(AchievementTransferGXDTO dto, AnalysisContext context) {
        // 只做简单映射，类型和备注可留空或默认
        AchievementTransfer entity = new AchievementTransfer();
        entity.setUsername(dto.getUsername());
        entity.setTransferName(dto.getTransferName());
        entity.setTransferAmount(dto.getTransferAmount());
        entity.setTransferYear(dto.getTransferYear());
//        entity.setTransferType(""); // 平台模板无类型
//        entity.setTransferNotes(""); // 平台模板无备注
        dataList.add(entity);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        service.saveAllFromDTO(dataList);
    }

    @Override
    public int getImportedCount() { return dataList.size(); }
    @Override
    public int getIgnoredCount() { return 0; }
}
